/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.suarte.webapp.action;

import com.suarte.core.UnitMeasure;
import java.io.Serializable;
import org.appfuse.service.GenericManager;


/**
 *
 * @author giovanella
 */
public class UnitMeasureForm extends BasePage implements Serializable {
    private GenericManager<UnitMeasure, Long> unitMeasureManager;
    private UnitMeasure unitMeasure = new UnitMeasure();
    private Long id;

    public void setUnitMeasureManager(GenericManager<UnitMeasure, Long> unitMeasureManager) {
        this.unitMeasureManager = unitMeasureManager;
    }

    public UnitMeasure getUnitMeasure() {
        return unitMeasure;
    }

    public void setUnitMeasure(UnitMeasure unitMeasure) {
        this.unitMeasure = unitMeasure;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public String delete() {
        unitMeasureManager.remove(unitMeasure.getId());
        addMessage("unitMeasure.deleted");

        return "list";
    }

    public String edit() {
        if (id != null) {
            unitMeasure = unitMeasureManager.get(id);
        } else {
            unitMeasure = new UnitMeasure();
        }

        return "edit";
    }

    public String add() {
        unitMeasure = new UnitMeasure();

        return "add";
    }

    public String save() {
        boolean isNew = (unitMeasure.getId() == null);
        unitMeasureManager.save(unitMeasure);

        String key = (isNew) ? "unitMeasure.added" : "unitMeasure.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
}
